package wzh.crm.db;

import org.json.JSONException;
import org.json.JSONObject;
import org.jsoup.Connection;

import java.util.List;

import wzh.crm.vo.ContactVo;

/**
 * Created by wangzehao on 2016/6/15.
 */
public class ContactDB extends WebServiceDB<ContactVo> {
    @Override
    protected ContactVo toBean(JSONObject json) throws JSONException {
        ContactVo model=new ContactVo();
        model.setId(json.getInt("contactsid"));
        model.set所属客户id(json.getInt("customerid"));
        model.set姓名(json.getString("contactsname"));
        model.set年龄(json.optInt("contactsage"));
        model.set用户性别(json.getString("contactsgender"));
        model.set手机(json.getString("contactsmobile"));
        model.set电话(json.getString("contactstelephone"));
        model.set邮箱(json.getString("contactsemail"));
        model.set地址(json.getString("contactsaddress"));
        model.set邮编(json.getString("contactszipcode"));
        model.setQQ号(json.getString("contactsqq"));
        model.set微信号(json.getString("contactswechat"));
        model.set旺旺号(json.getString("contactswangwang"));
        model.set部门名称(json.getString("contactsdeptname"));
        model.set职位(json.optInt("contactsposition"));
        model.set备注(json.getString("contactsremarks"));
        return model;
    }

    @Override
    protected void toPost(ContactVo model, Connection c) {
        c.data("contactsid",Integer.toString(model.getId()));
        c.data("customerid",Integer.toString(model.get所属客户id()));
        c.data("contactsname",model.get姓名());
        c.data("contactsage",Integer.toString(model.get年龄()));
        c.data("contactsgender",model.get用户性别());
        c.data("contactsmobile",model.get手机());
        c.data("contactstelephone",model.get电话());
        c.data("contactsemail",model.get邮箱());
        c.data("contactsaddress",model.get地址());
        c.data("contactszipcode",model.get邮编());
        c.data("contactsqq",model.getQQ号());
        c.data("contactswechat",model.get微信号());
        c.data("contactswangwang",model.get旺旺号());
        c.data("contactsdeptname",model.get部门名称());
        c.data("contactsposition",Integer.toString(model.get职位()));
        c.data("contactsremarks",model.get备注());
    }

    @Override
    protected String listQueryMethod() {
        return "common_contacts_json";
    }

    @Override
    protected String idQueryMethod() {
        return null;
    }

    @Override
    protected String createMethod() {
        return "contact_create_json";
    }

    @Override
    protected String modifyMethod() {
        return "contact_modify_json";
    }
}
